import json

import allure

from test_pom.test4_八爪云接口自动化测试.base_api.base_api import BaseApi


class ChannelApi(BaseApi):
    base_url = "http://api.wxorder.taover.com"

    @allure.step("创建渠道")
    def create_channel(self, data):
        create_url = f"{self.base_url}/v1/wxorderchannel"
        req = {
            "method": "post",
            "url": create_url,
            "json": data,
            "headers": {
                "Authorization": self.get_token()
            }
        }
        res = self.send_api(req)
        return res

    @allure.step("查询渠道")
    def search_channel(self,data):
        search_url = f"{self.base_url}/v1/wxorderchannel"
        req = {
            "method": "get",
            "url": search_url,
            "params": data,
            "headers": {
                "Authorization": self.get_token()
            }
        }
        res = self.send_api(req)
        return res

    @allure.step("删除渠道")
    def delete_channel(self, channel_id):
        delete_url = f"{self.base_url}/v1/wxorderchannel/{channel_id}"
        req = {
            "method": "delete",
            "url": delete_url,
            "headers": {
                "Authorization": self.get_token()
            }
        }
        res = self.send_api(req)
        return res


